<?php
class Verify extends MY_Controller{
	public function __construct(){
		parent::__construct();
		$data_ses=array(
			"current_language" => array('code' => 'en'),
			"default_language" => array('code' => 'en')
		);
		$this->session->set_userdata($data_ses);
	}
	public function login(){
		$data['template']="verify/login_view";
		if($this->input->post("ok")){
			$this->form_validation->set_rules("txtuser","Username","required");
			$this->form_validation->set_rules("txtpass","Password","required");
			$u = $this->input->post("txtuser");
			$p = md5(md5($this->input->post("txtpass")));
			$this->load->Model(array("Madmin"));
			$data=$this->Madmin->check_login($u,$p);
			if($this->form_validation->run() == FALSE || $data == FALSE){
				if($u && $p){
					$data['error']=trans('error_login');
				}
			}else{
				$id = $data['admin_id'];
				$data_ses=array(
					"ses_adminid" => $id,
					"ses_admin" => $data['admin_name'],
					"ses_fullname" => $data['admin_fullname'],
				);
				$this->session->set_userdata($data_ses);
				$this->session->set_flashdata("login", trans('message_login_success'));
				redirect(base_url().'admincp/dashboard');
			}
		}
		$this->load->view("verify/template",$data);
	}
	public function logout(){
		if(!isset($this->session->userdata['ses_admin'])){
			$user = "";
		}else{
			$user = $this->session->userdata['ses_admin'];
		}
		$this->session->sess_destroy();
		redirect(base_url()."verify/login");	
	}
}